-
-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose the fact that templates implement Display #654
Conversation
askama_shared/src/lib.rs
Outdated
/// Renders the template to the given `writer` buffer | ||
/// Helper method which allocates a new `Vec<u8>` and renders into it | ||
#[inline] | ||
fn render_bytes(&self) -> Result<Vec<u8>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't meet my cost/benefit bar, conversions with String::into_bytes()
should be easy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
askama_shared/src/lib.rs
Outdated
fn render_into(&self, writer: &mut (impl std::fmt::Write + ?Sized)) -> Result<()>; | ||
|
||
/// Renders the template to the given `writer` io buffer | ||
#[inline] | ||
fn render_into_io(&self, writer: &mut (impl std::io::Write + ?Sized)) -> std::io::Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one seems reasonable, though the name seems a little unwieldy. Maybe write_into()
? That's technically somewhat ambitious between impl std::fmt::Write
and impl std::io::Write
but that doesn't seem like a big deal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed.
This is a quite useful feature, because you can use templates in format!(), format_args!(), etc.
It might not be immediately obvious to everyone how easy it is to use Askama template with std::io (e.g. files) instead of std::fmt, so this PR adds a few helper methods to make this more obvious to novice users.
Rebased on #653.
This PR consists of two parts:
Expose the fact that templates implement Display
This is a quite useful feature, because you can use templates in format!(), format_args!(), etc.
Add io::writer helper methods
It might not be immediately obvious to everyone how easy it is to use Askama template with std::io (e.g. files) instead of std::fmt, so this PR adds a few helper methods to make this more obvious to novice users.
(Nb. the "novice user" is me in this case :) )